package com.jh.user.pojo.freeQuick;

import cn.jh.common.pay.utils.InEntity;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;


/**
 * 消费（刷卡）支付。
 *
 * @author Fuchun
 * @since 1.0
 */
public class InConsumption extends InEntity {

    private String outSerialNo;
    private String cardNo;
    private String cardCvn2;
    private String cardExpired;
    private BigDecimal amount;
    private String productName;
    private String productDesc;
    private String notifyUrl;

    @Override
    protected void applySign(@NotNull List<String> parts) {
        parts.add(outSerialNo);
        parts.add(cardNo);
        if (cardCvn2 != null)
            parts.add(cardCvn2);
        if (cardExpired != null)
            parts.add(cardExpired);
        parts.add(amount.toPlainString());
        parts.add(productName);
        parts.add(productDesc);
        parts.add(notifyUrl);
    }

    @JsonProperty("out_serial_no")
    public String getOutSerialNo() {
        return outSerialNo;
    }

    public void setOutSerialNo(String outSerialNo) {
        this.outSerialNo = outSerialNo;
    }

    @JsonProperty("card_no")
    public String getCardNo() {
        return cardNo;
    }

    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }

    @JsonProperty("card_cvn2")
    public String getCardCvn2() {
        return cardCvn2;
    }

    public void setCardCvn2(String cardCvn2) {
        this.cardCvn2 = cardCvn2;
    }

    @JsonProperty("card_expired")
    public String getCardExpired() {
        return cardExpired;
    }

    public void setCardExpired(String cardExpired) {
        this.cardExpired = cardExpired;
    }

    @JsonProperty("amount")
    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount != null ? amount.setScale(2, RoundingMode.HALF_UP) : null;
    }

    @JsonProperty("product_name")
    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    @JsonProperty("product_desc")
    public String getProductDesc() {
        return productDesc;
    }

    public void setProductDesc(String productDesc) {
        this.productDesc = productDesc;
    }

    @JsonProperty("notify_url")
    public String getNotifyUrl() {
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    @Override
    protected void applyToString(MoreObjects.ToStringHelper tsh) {
        tsh.add("outSerialNo", outSerialNo)
                .add("cardNo", cardNo)
                .add("cardCvn2", cardCvn2)
                .add("cardExpired", cardExpired)
                .add("amount", amount)
                .add("productName", productName)
                .add("productDesc", productDesc)
                .add("notifyUrl", notifyUrl);
    }
}
